package com.xr.system;

import com.bstek.dorado.common.*;
import com.bstek.dorado.data.*;
import com.bstek.dorado.data.db.DBStatement;
import com.bstek.dorado.view.*;
import com.bstek.dorado.view.data.*;
import com.bstek.dorado.view.control.*;

/**
 * handoverViewModel
 */
public class handoverViewModel extends DefaultViewModel {
  protected void initControls()
      throws Exception {
    super.initControls();
    // Add your code here
  }

  public void handOverAction(ParameterSet parameters, ParameterSet outParameters)
      throws Exception {
	  DBStatement dbs = new DBStatement();
	  Dataset dsList=getDataset("datasetAllModule");
	  Dataset ds=getDataset("datasetCdn");
	  String empId=ds.getString("EMPLOYEE_ID");
	  String empName=ds.getString("EMPLOYEE_NAME");
	  String newEmpName=ds.getString("NEW_EMPLOYEE_NAME");
	  String newEmpId=ds.getString("NEW_EMPLOYEE_ID");
	  dsList.moveFirst();
	  while(!dsList.isLast()){
		if(dsList.getString("NAME").equalsIgnoreCase("wkf_activity_def")){
			  dbs.setSql("update wkf_activity_def set remindman_id="+newEmpId+" where remindman_id="+empId);
			  dbs.execute();
		}
		if(dsList.getString("NAME").equalsIgnoreCase("rt_oos_emp_role")){
			dbs.setSql("update rt_oos_emp_role set employee_id="+newEmpId+" where employee_id="+empId);
			 dbs.execute();
		}
		if(dsList.getString("NAME").equalsIgnoreCase("wa_send")){
			dbs.setSql("update wa_send set owner_id="+newEmpId+" where owner_id="+empId);
			 dbs.execute();
		}
		if(dsList.getString("NAME").equalsIgnoreCase("WA_OOC_CLASS_PLAN")){
			dbs.setSql("update WA_OOC_CLASS_PLAN set manager_id="+newEmpId+" where manager_id="+empId);
			 dbs.execute();
		}
		if(dsList.getString("NAME").equalsIgnoreCase("wa_oos_class")){
			dbs.setSql("update WA_OOC_CLASS_PLAN set manager_id="+newEmpId+" where manager_id="+empId);
			 dbs.execute();
		}
		if(dsList.getString("NAME").equalsIgnoreCase("WA_CHECK_CLASS")){
			  dbs.setSql("update WA_CHECK_CLASS set prower_man_ids=Replace(prower_man_ids,','||'"+empId+"',','||'"+newEmpId+",'),prower_man_names=Replace(prower_man_names,','||'"+empName+"',','||'"+newEmpName+",') where instr(prower_man_ids,',"+empId+",')>0 and instr(prower_man_names,',"+empName+",')>0 ");
			  dbs.execute();
			  dbs.setSql("update WA_CHECK_CLASS set prower_man_ids="+newEmpId+",prower_man_names='"+newEmpName+"' where prower_man_ids ='"+empId+"' and prower_man_names='"+empName+"'");
			  dbs.execute();
			  dbs.setSql("update WA_CHECK_CLASS set prower_man_ids="+newEmpId+",prower_man_names='"+newEmpName+"' where prower_man_ids ='"+empId+"' and prower_man_names='"+empName+"'");
			  dbs.execute();
			  dbs.setSql("update WA_CHECK_CLASS set prower_man_ids=substr(prower_man_ids,0,length(prower_man_ids)-length(',"+empId+"'))||',"+newEmpId+"',prower_man_names=substr(prower_man_names,0,length(prower_man_names)-length(',"+empName+"'))||',"+newEmpName+"'  where prower_man_ids like '%,"+empId+"' and prower_man_names='%,"+empName+"'");
			  dbs.execute();
			  dbs.setSql("update WA_CHECK_CLASS set prower_man_ids='"+newEmpId+",'||substr(prower_man_ids,length(',"+empId+"'),length(prower_man_ids)),prower_man_names='"+newEmpName+",'||substr(prower_man_names,length(',"+empName+"'),length(prower_man_names))  where prower_man_ids like '"+empId+",%' and prower_man_names='"+empName+",%'");
			  dbs.execute();
		}
		 
		  dsList.moveNext();
	  }
	 
	  
	  dbs.close();
    //super.doUpdateData(parameters, outParameters);
  }

  
}
